package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.Ship;
import asteroids.model.programs.parsing.types.*;

/**
 * A class of logic or-expressions.
 * A logic or-expression returns false if and only if the left-hand operand and the right-hand operand are false.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public class OrExpr extends LogicalExpr {

	public OrExpr(Expression e1, Expression e2, int line, int column) {
		super(e1, e2,line, column);	
	}

	@Override
	public BooleanLiteral eval(Ship ship, Map<String, Type> globals) {
		if(getLeftOperand().eval(ship, null) instanceof BooleanLiteral && getRightOperand().eval(ship, null) instanceof BooleanLiteral){
			BooleanLiteral bt1 = (BooleanLiteral) getLeftOperand().eval(ship, null);
			BooleanLiteral bt2 = (BooleanLiteral) getRightOperand().eval(ship, null);
			return new BooleanLiteral(bt1.getValue() || bt2.getValue());
		}
		return new BooleanLiteral();
	}
}
